package com.zhijiang.hospital.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhijiang.hospital.entity.ComDeptBedsnum;
import com.zhijiang.hospital.mapper.ComDeptBedsnumMapper;
import com.zhijiang.hospital.service.ComDeptBedsnumService;
import com.zhijiang.util.BaseQuery;
import com.zhijiang.util.NumberUtils;
import com.zhijiang.util.PageList;
import com.zhijiang.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_data
 * @description
 * @date 2023-02-20 15:18:51
 */
@Service
public class ComDeptBedsnumServiceImpl implements ComDeptBedsnumService {
    @Autowired
    private ComDeptBedsnumMapper comDeptBedsnumMapper;

    @Override
    public List<ComDeptBedsnum> findComDeptBedsNum(BaseQuery baseQuery) {
        List<ComDeptBedsnum> comDeptBedsNums = comDeptBedsnumMapper.findAll(baseQuery.getStartTime(), baseQuery.getEndTime());
        List<ComDeptBedsnum> list = comDeptBedsNums.stream().filter(a -> a.getDeptName().equals("全部")).collect(Collectors.toList());
        return list;
    }

    @Override
    public PageList<ComDeptBedsnum> findComDeptBedsNumByPageList(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getPage(), baseQuery.getPageSize());
        List<ComDeptBedsnum> comDeptBedsNums = comDeptBedsnumMapper.findAll(baseQuery.getStartTime(), baseQuery.getEndTime());
        PageInfo<ComDeptBedsnum> pageInfo = new PageInfo<>(comDeptBedsNums);
        Integer pages = NumberUtils.totalPages(pageInfo.getTotal(), baseQuery.getPageSize());
        PageList pageList = new PageList(pageInfo.getTotal(), pageInfo.getList(), baseQuery.getPage(), baseQuery.getPageSize(), pages);
        return pageList;
    }

    @Override
    public Map<String, List> loadDateChart() {
        Map<String, List> map = new HashMap<>();
        List<String> deptNameList = new ArrayList<>();
        List<Integer> hospitalBedList = new ArrayList<>();
        return map;
    }

    @Override
    public List<ComDeptBedsnum> loadYear() {
        DateTime dateTime = DateUtil.beginOfYear(new Date());
        DateTime dateTime1 = DateUtil.endOfYear(new Date());
        String startTime = Convert.toStr(dateTime);
        String endTime = Convert.toStr(dateTime1);
        BaseQuery baseQuery = new BaseQuery();
        baseQuery.setStartTime(startTime);
        baseQuery.setEndTime(endTime);
        List<ComDeptBedsnum> list = comDeptBedsnumMapper.findAll(baseQuery.getStartTime(), baseQuery.getEndTime());
        return list;
    }

    @Override
    public List<ComDeptBedsnum> loadLastYearData() {
        Date nextYearPreDay = TimeUtil.getNextYearPreDay();
        DateTime dateTime3 = DateUtil.beginOfYear(nextYearPreDay);
        DateTime dateTime4 = DateUtil.endOfYear(nextYearPreDay);
        String startTime = TimeUtil.format(dateTime3);
        String endTime = TimeUtil.format(dateTime4);
        BaseQuery baseQuery = new BaseQuery();
        baseQuery.setStartTime(startTime);
        baseQuery.setEndTime(endTime);
        List<ComDeptBedsnum> all = comDeptBedsnumMapper.findAll(baseQuery.getStartTime(), baseQuery.getEndTime());
        return all;
    }


}
